package com.hmall.trade.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.hmall.api.client.ItemClient;
import com.hmall.trade.domain.po.OrderDetail;
import com.hmall.trade.mapper.OrderDetailMapper;
import com.hmall.trade.service.IOrderDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单详情表 服务实现类
 * </p>
 *
 * @author 虎哥
 * @since 2023-05-05
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {

    @Resource
    private ItemClient itemClient;

    @Override
    public void recoverStock(Long orderId) {

        List<OrderDetail> orderDetailList = this.lambdaQuery()
                .eq(OrderDetail::getOrderId, orderId)
                .list();

        Map<Long, Integer> itemNumMap = orderDetailList.stream().collect(Collectors.toMap(OrderDetail::getItemId, OrderDetail::getNum));
        itemClient.recoverStock(itemNumMap);


    }
}
